package com.shilei.spring.util;

import java.util.HashSet;
import java.util.Set;
import java.util.function.Consumer;

/**
 * @author 石雷
 * shilei1@jiayuan.com
 * 2021/8/31/031 17:30
 */
public class AnnotationUtil {

    /**
     * 根据注解获取所有类
     * @param pack
     * @param annotations
     * @return
     */
    public static Set<Class<?>> getClassByAnnotation(String pack,Set<Class> annotations){
        Set<Class<?>> classesResult=new HashSet<>();
        Set<Class<?>> classes = PackageUtil.getClasses(pack);
        for(Class c:classes){
            annotations.forEach(new Consumer<Class>() {
                @Override
                public void accept(Class aClass) {
                    // 获取有Component 的类
                    if(c.isAnnotationPresent(aClass)){
                        classesResult.add(c);
                    }
                }
            });

        }
        return classesResult;
    }
}
